<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Model {

	   function getPageCategories(){
      $data = $this->db->get('categories');
      return $data->result();
    }

    function addCategory($name){
  	$data = array('name'=>$name,
    		 );
    	$this->db->insert('categories', $data);
    }

    
    function getCategoryById($id){
    	$this->db->where('id', $id);
    	$data = $this->db->get('categories');
      return $data->result();
    }

	function belongsToMe(){

	}   
	
	function pageCount(){
		$query = $this->db->get('deals');
		$rowcount = $query->num_rows();
		$pagecount = 0;
		if($rowcount % 20 == 0){
			$pagecount = intval($rowcount/20);
		}else{
			$pagecount = intval($rowcount/20)+1;
		}
		return $pagecount;
	} 

  function deleteCategory($id){
    $this->db->where('id', $id);
    $this->db->delete('categories'); 
  }

  function editCategory($id, $name){
    $this->db->where('id',$id);
    $this->db->set('name',$name);
    $this->db->update('categories');
  }

}